<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/12
 * Time: 11:00
 */

namespace app\educational\model;


use think\Model;

class LogModel extends Model
{
    public function listHistory($filter)
    {
        $where=[];
        if(!empty($filter['user_login'])) {
            //用户名称
            $where['u.user_login'] = ['like', '%'.trim($filter['user_login']).'%'];
        }
        $homework_starttime = empty($filter['homework_starttime']) ? 0 : strtotime($filter['homework_starttime']);
        $homework_endtime   = empty($filter['homework_endtime']) ? 0 : strtotime($filter['homework_endtime']);
        if (!empty($homework_starttime) && !empty($homework_endtime)) {
            $where['lh.create_time'] = [['>= time', $homework_starttime], ['<= time', $homework_endtime]];
        } else {
            if (!empty($homework_starttime)) {
                $where['lh.create_time'] = ['>= time', $homework_starttime];
            }
            if (!empty($homework_endtime)) {
                $where['lh.create_time'] = ['<= time', $homework_endtime];
            }
        }
        $data=$this->alias('lh')->field('lh.*,u.user_login')
            ->join('user u','u.id=lh.user_id')
            ->where($where)
            ->order('lh.id desc')
            ->paginate(10,false,['query' => $filter]);
        return $data;
    }
}